﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ImdbServices;
using WindowsLive.Writer.Api;

namespace InsertIMDBInfo
{
    public class PluginSettings
    {
        private IProperties m_properties;
        private const string IMDBLINK = "IMDBLINK";
        private const string FILMTITLE = "FILMTITLE";
        private const string FILMYEAR = "FILMYEAR";
        private const string FILMACTORS = "FILMACTORS";
        private const string FILMDESCRIPTION = "FILMDESCRIPTION";
        private const string IMAGEURL = "IMAGEURL";
        private const string DISPLAYIMAGE = "DISPLAYIMAGE";
        private const string DISPLAYTITLE = "DISPLAYTITLE";
        private const string DISPLAYACTORS = "DISPLAYACTORS";
        private const string DISPLAYDESCRIPTION = "DISPLAYDESCRIPTION";
        private const string DISPLAYYEAR = "DISPLAYYEAR";
        private const string ALIGNMENT = "ALIGNMENT";
        private const string CUSTOMTEMPLATE = "CUSTOMTEMPLATE";
        private const string DEFAULTTEMPLATE = "DEFAULTTEMPLATE";

        public PluginSettings(IProperties properties)
        {
            m_properties = properties;
        }

        public string IMDbLink
        {
            get { return m_properties.GetString(IMDBLINK, ""); }
            set { m_properties.SetString(IMDBLINK, value); }
        }

        public string Title
        {
            get { return m_properties.GetString(FILMTITLE, ""); }
            set { m_properties.SetString(FILMTITLE, value); }
        }

        public string Year
        {
            get { return m_properties.GetString(FILMYEAR, ""); }
            set { m_properties.SetString(FILMYEAR, value); }
        }

        public string Actors
        {
            get { return m_properties.GetString(FILMACTORS, ""); }
            set { m_properties.SetString(FILMACTORS, value); }
        }

        public string Description
        {
            get { return m_properties.GetString(FILMDESCRIPTION, ""); }
            set { m_properties.SetString(FILMDESCRIPTION, value); }
        }

        public string ImageUrl
        {
            get { return m_properties.GetString(IMAGEURL, ""); }
            set { m_properties.SetString(IMAGEURL, value); }
        }

        public bool DisplayActors
        {
            get { return m_properties.GetBoolean(DISPLAYACTORS, true); }
            set { m_properties.SetBoolean(DISPLAYACTORS, value); }
        }

        public bool DisplayDescription
        {
            get { return m_properties.GetBoolean(DISPLAYDESCRIPTION, true); }
            set { m_properties.SetBoolean(DISPLAYDESCRIPTION, value); }
        }

        public bool DisplayImage
        {
            get { return m_properties.GetBoolean(DISPLAYIMAGE, true); }
            set { m_properties.SetBoolean(DISPLAYIMAGE, value); }
        }

        public bool DisplayTitle
        {
            get { return m_properties.GetBoolean(DISPLAYTITLE, true); }
            set { m_properties.SetBoolean(DISPLAYTITLE, value); }
        }

        public bool DisplayYear
        {
            get { return m_properties.GetBoolean(DISPLAYYEAR, true); }
            set { m_properties.SetBoolean(DISPLAYYEAR, value); }
        }

        public int Alignment
        {
            get { return m_properties.GetInt(ALIGNMENT, 0); }
            set { m_properties.SetInt(ALIGNMENT, value); }
        }

        public string CustomTemplate
        {
            get { return m_properties.GetString(CUSTOMTEMPLATE, "true,true,true,true,true"); }
            set { m_properties.SetString(CUSTOMTEMPLATE, value); }
        }

        public string DefaultTemplate
        {
            get { return m_properties.GetString(DEFAULTTEMPLATE, "true,true,true,true,true"); }
            set { m_properties.SetString(DEFAULTTEMPLATE, value); }
        }

        public string FullTemplate = "True,True,True,True,True";
        public string TinyTemplate = "False,False,True,False,False";
        public string MediumTemplate = "False,True,True,True,False";

        public bool[] ParseTemplateOptions(string options)
        {
            char[] c = { ',' };
            List<bool> result = new List<bool>();
            string[] o = options.Split(c, StringSplitOptions.RemoveEmptyEntries);
            foreach (string s in o)
                result.Add(Convert.ToBoolean(s));

            return result.ToArray();
        }

    }
}
